<?php
/**
 * 后台:医师管理
 */
namespace App\Http\Controllers\Admin;


use App\Models\Depart;
use App\Models\Doctor;
use App\Models\Worktime;

class DoctorController extends BaseController
{

    public function __construct(Doctor $doctor,Worktime $worktime, Depart $depart)
    {
        parent::__construct();
        $this->doctor = $doctor;
        $this->depart = $depart;
        $this->worktime = $worktime;
    }

    public function getTimeArea(){
         $res = $this->doctor->getWorkTime(request());
         return ajax_return($res);
    }

    //医师管理主页
    public function getIndex()
    {
        $rows = $this->doctor->getDoctorList(request());
        $departs = $this->depart->getCachAllList();
        $did = request('did',0);
        $keyword = request('keyword','');
        return view('admin.doctor.index',compact('rows','departs','did','keyword'));
    }
    //医师添加页面
    public function getAdd()
    {
        $types = apiCurl('regType');
        $kefu = apiCurl('getKfList','','http://155m5k1578.iask.in:30552/askapi/?service=Index');
        $kefu = $kefu['data'];
        $departs = $this->depart->getCachAllList();
        return view('admin.doctor.add',compact('departs','types','kefu'));
    }

    //处理添加医师请求
    public function postAdd()
    {
        //接收表单提交的数据
        $res = $this->doctor->addDcotor(request());
        return redirect()->back()->with('message', $res)->withInput();
    }

    public function getAjaxDoctors()
    {
        $doctors = apiCurl('regDoctors',request('depart_id',1));
        return ajax_return($doctors);
    }


    //医师编辑页面
    public function getEdit(){

        $data = $this->doctor->getOne(['id'=>request('id')]);
        $departs = $this->depart->getCachAllList();
        $kefu = apiCurl('getKfList','','http://155m5k1578.iask.in:30552/askapi/?service=Index');
        $kefu = $kefu['data'];
        $types = apiCurl('regType');
        $doctors = apiCurl('regDoctors',$data['depart_id']);
//        dd($doctors);
        return view('admin.doctor.edit',compact('data','types','departs','doctors','kefu'));
    }

    public function postSort(){
        $res = $this->doctor->dealSort(request());
        return ajax_return($res);
    }

    //处理编辑医师请求
    public function postEdit(){
        $res = $this->doctor->editDoctor(request());
        return redirect()->back()->with('message', $res)->withInput();
    }

    public function getModifyStatus(){
        $res = $this->doctor->modifyDoctor(request());
        return ajax_return($res);
    }
    public function getChangeHot(){
        $res = $this->doctor->changeHot(request());
        return ajax_return($res);
    }

    //处理删除医师请求
    public function getDel(){
        $res = $this->doctor->delDoctor(request());
        return ajax_return($res);
    }

    //根据id获取医师信息
    public function getDoctorInfo(){
         $res = $this->doctor->getDoctorById(request());
         return ajax_return($res);
    }

    public function getWorkTime(){
         $res = $this->worktime->getWorkTime(request());
         return ajax_return($res);
    }

    public function getChangeState(){
         $res = $this->worktime->changeWorkSate(request());
         return ajax_return($res);
    }

    public function getChangeDocState(){
        $res = $this->doctor->changeWorkSate(request());
        return ajax_return($res);
    }

    public function getWorkTimeById(){
         $res = $this->worktime->getWorkTimeById(request());
         return ajax_return($res);
    }

    // 删除坐诊计划
    public function getDelWorkTime(){
         $res = $this->worktime->getDelWorkTime(request());
         return ajax_return($res);
    }

    public function getWorkTimeIndex(){
        $res = $this->doctor->getWorkTimeIndex(request());
        return view("admin.doctor.worktime",compact('res'));
    }

    public function getWorkTimeList(){
        $res = $this->worktime->getWorkTimeListById(request());
        return view("admin.doctor.worktimelist",compact('res'));
    }

    /**
     * 添加坐诊日期
     */
    public function postAddWorkTime(){
        $res = $this->worktime->addDcotorWorkTime(request());
        return redirect()->back()->with('message', $res)->withInput();
    }

    /**
     * 编辑坐诊日期
     */
    public function getEditWorkTime(){
        $res = $this->doctor->getworkTime(['type'=>0]);
        $data = $this->worktime->getWorkTimeByIdOne(request());
        return view("admin.doctor.editworktime",compact('res','data'));
    }

    /**
     * 添加坐诊日期
     */
    public function getAddWorkTime(){
        $res = $this->doctor->getworkTime(['type'=>0]);
        $daylist = $this->doctor->getDayList();
        return view("admin.doctor.addworktime",compact('res','daylist'));
    }

    public function getTest(){
         $res = $this->doctor->test(request());
    }

    /**
     * 添加坐诊日期
     */
    public function postEditWorkTime(){
        $res = $this->worktime->editDcotorWorkTime(request());
        return redirect()->back()->with('message', $res)->withInput();
    }

    public function getLst()
    {
        $res = $this->doctor->lstDoctor();
        return view('admin.doctor.lst');
    }


}
